package battleship;

import battleship.boat.Boat;
import battleship.player.Player;

//nothing todo for model view
public class Loop { //all methods which will occur within the loop
	
	private static int turns; //if the player hits the other player and is allowed to strike again, this counts as being the same turn, so winning a battle in 1 turn is possible in theory
	private static boolean win = false;
	private static Boat lastHitBoat = null;
	private static Player lastTurn; 				//player who did the last turn, used to determine winner
	//	<getters>
	
	public static int getTurns(){
		return turns;
	}
	
	public static void setTurns (int turns) {
		Loop.turns = turns;
	}
	
	public static Player getLastTurn()
	{
		return lastTurn;
	}
	
	public static boolean getWin(){
		return win;
	}
	
	public static Boat getLastHitBoat(){
		return lastHitBoat;
	}
	
	/**
	 * when a boat sunk this is used to determine if he won aswell
	 * 
	 * @param player the supposed winner
	 * @return true if the player won, false if not
	 */
	public static boolean getWin(Player player){ 
		Player player2 = Setup.getPlayer2(player);

		
		//check player2's boats
		for(int boatNo = 0; boatNo < player2.getField().getBoats().length; boatNo++){ 
			if(!player2.getField().getBoats()[boatNo].getSunk()){
				return false;
			}
		}
		return true;
	}
	
	//	</getters>
	
	//  <setters>
	
	public static void setWin(boolean win){
		Loop.win = win;
	}
	
	public static void increaseTurns(){
		turns++;
	}
	
	public static void setLastHitBoat(Boat lastHit){
		Loop.lastHitBoat = lastHit;
	}
	
	public static void setLastTurn(Player lastTurn)
	{
		Loop.lastTurn = lastTurn;
	}
	
	//</setters>
}
